package com.macro.mall.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.macro.mall.common.api.CommonResult;
import com.macro.mall.dto.BmsConfigParam;
import com.macro.mall.model.BmsConfig;
import com.macro.mall.service.BmsConfigService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;

/**
 * 系统配置 Created by macro on 2018/4/26.
 */
@Controller
@Api(tags = "bmsConfigController")
@Tag(name = "bmsConfigController", description = "系统配置表")
@RequestMapping("/bmsConfig")
public class BmsConfigController {

    @Autowired
    private BmsConfigService baseService;

    @ApiOperation("查询【能别用就别用，想用也别用】")
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<BmsConfig> getList(@RequestBody BmsConfigParam bmsConfigParam) {
        BmsConfig bmsConfigList = baseService.getList(bmsConfigParam);
        return CommonResult.success(bmsConfigList);
    }

    @ApiOperation("根据code获取")
    @RequestMapping(value = "/getByCode/{code}", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<?> getByCode(@PathVariable String code) {
        try {
            return CommonResult.success(baseService.getByCode(code));
        } catch (Exception e) {
            return CommonResult.failed(e.getMessage());
        }
    }

    @ApiOperation("添加")
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> create(@RequestBody BmsConfigParam param) {
        try {
            baseService.create(param);
            return CommonResult.success();
        } catch (Exception e) {
            return CommonResult.failed(e.getMessage());
        }
    }

    @ApiOperation("修改")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> update(@RequestBody BmsConfigParam param) {
        try {
            baseService.update(param);
            return CommonResult.success();
        } catch (Exception e) {
            return CommonResult.failed(e.getMessage());
        }
    }

}
